/**
 * File name: ARFFFileFunctionWriter.java Author: Willard Wang Create date: Jul
 * 28, 2013
 */
package edu.sjtu.se.prophet.io;

import java.io.IOException;

import edu.sjtu.se.prophet.graph.Graph;
import edu.sjtu.se.prophet.graph.Node;

/**
 * @author deathspeeder
 * 
 */
public class ARFFFileFunctionWriter extends AbstractARFFFileWriter {

    public ARFFFileFunctionWriter() {
        outFileName = "data-function.arff";
        arffName = "functions";
    }

    /*
     * (non-Javadoc)
     * 
     * @see edu.sjtu.se.prophet.io.AbstractARFFFileWriter#writeData()
     */
    @Override
    protected void writeData() throws IOException {
        br.append("@DATA\n");
        for (Graph graph : graphs) {
            for (Node node : graph.getNodes()) {
                StringBuffer buffer = new StringBuffer();
                // boolean nullFlag = false;
                for (int i = 0; i < VALID_METRICS.length; i++) {
                    Object obj = node.getMetrics().get(VALID_METRICS[i]);
                    // if (obj == null)
                    // nullFlag = true;
                    buffer.append(obj);
                    buffer.append(",");
                }
                buffer.append(getLevel((Integer) node.getMetrics().get(
                        IOCommon.BUG_COUNT)));
                // if (!nullFlag)
                br.append(buffer.toString() + " % " + node.getId() + "\n");
            }
        }
    }

}
